package smashedapples.mvc
{
	import flash.events.Event;
	import smashedapples.core.smashedns;
	import mx.containers.Canvas;
	import mx.core.UIComponent;
	use namespace smashedns;


	[Style( name="controller", type = "Class", inherit = "no" )]


	public class View extends Canvas
	{
		/**
		 *    internal namespace controller
		 */
		smashedns var $controller:Controller;


		[Inspectable(enumeration="true,false",defaultValue="false")]
		
		public var debug:Boolean = false;

		/**
		 *
		 *  Constructor
		 *
		 */
		public function View()
		{
			super();
			//this.percentHeight = 100;
			//this.percentWidth = 100;
		}

		override protected function commitProperties():void
		{
			super.commitProperties();

			var ControllerClass:Class = this.getStyle( "controller" );
			if( ControllerClass != null )
			{
				smashedns::$controller = new ControllerClass();
				smashedns::$controller.$view = this;
			}
		}


		/**
		 *
		 *  We override the dispatchEvent function so that we can catch all events coming from
		 *  our component
		 *
		 * @param event
		 * @return Boolean
		 *
		 */

		override public function dispatchEvent( event:Event ):Boolean
		{
			if( smashedns::$controller != null )
				smashedns::$controller.execute( event );

			return super.dispatchEvent( event );
		}
		
		
	
		


	}
}